// --------------------------------------------------------------------------------------------------------------------
// <copyright file="StorageCredentialsExtensions.cs" company="AzureContrib (Open source library http://azurecontrib.codeplex.com)">
//   Microsoft Public License (Ms-PL)
// </copyright>
// <summary>
//   Extension methods for <see cref="StorageCredentials" />
// </summary>
// --------------------------------------------------------------------------------------------------------------------

using Microsoft.WindowsAzure;

namespace AzureContrib.WindowsAzure.StorageClient
{
	/// <summary>
	/// Extension methods for <see cref="StorageCredentials"/>
	/// </summary>
	public static class StorageCredentialsExtensions
	{
		/// <summary>
		/// Check to see if the credentials are the ones used for development storage.
		/// </summary>
		/// <param name="storageCredentials">Chredentials to check.</param>
		/// <returns>True if the credentials are the development storage credentials.</returns>
		public static bool AreDevelopmentStorageCredentials(this StorageCredentials storageCredentials)
		{
			var credentials = CloudStorageAccount.DevelopmentStorageAccount.Credentials;
			return new StorageCredentialsComparer().Equals(storageCredentials, credentials);
		}

		/// <summary>
		/// Check to see if the credentials are the ones used for development storage.
		/// </summary>
		/// <param name="storageCredentials">Chredentials to check.</param>
		/// <returns>True if the credentials are the development storage credentials.</returns>
		public static bool AreDevelopmentStorageCredentials(this IStorageCredentials storageCredentials)
		{
			return AreDevelopmentStorageCredentials(storageCredentials.Unwrap());
		}

		/// <summary>
		/// Wrap the concrete <see cref="StorageCredentials"/> into a <see cref="IStorageCredentials"/>
		/// </summary>
		/// <param name="credentials">The credentials to wrap</param>
		/// <returns>The wrapped <see cref="IStorageCredentials"/>.</returns>
		public static IStorageCredentials Wrap(this StorageCredentials credentials)
		{
			return new StorageCredentialsWrapper(credentials);
		}

		/// <summary>
		/// Unwrap a <see cref="IStorageCredentials"/> back into the <see cref="StorageCredentials"/>
		/// </summary>
		/// <param name="credentials">The credentials contract to unwrap</param>
		/// <returns>The wrapped <see cref="IStorageCredentials"/>.</returns>
		public static StorageCredentials Unwrap(this IStorageCredentials credentials)
		{
			return ((StorageCredentialsWrapper)credentials).WrappedCredentials as StorageCredentials;
		}
	}
}